<template>
  <div class="ProductList">
    <!-- 头部 -->
    <div class="dark-top">
      <a @click="goback" class="page-back"><div></div></a>
      <div class="page-title">
        <font style="vertical-align: inherit;">{{ statusProduct }}</font>
      </div>
    </div>
    <!-- 列表内容 -->
    <div class="dark-body">
      <!-- 热卖商品 -->
      <mt-loadmore
        v-show="contentShow"
        v-infinite-scroll="loadMore"
        infinite-scroll-disabled="busy"
        infinite-scroll-distance="10"
        infinite-scroll-immediate-check="true"
      >
        <div
          class="hot_saleval"
          v-for="item in productDataList"
          :key="item.id"
          @click="goGoodsDetails(item.id)"
        >
          <div class="hot_content_box">
            <div class="hot_div_img box_left">
              <div
                :style="{ backgroundImage: 'url(' + item.picture + ')' }"
              ></div>
            </div>
            <div class="hot_div_brief box_right">
              <h4>{{ item.name }}</h4>
              <p>规格：{{ item.gauge }}</p>
              <p>{{ item.brief }}</p>
              <div>
                <span class="span_yuan">￥{{ item.price }}</span>
                <span class="span_button">预购</span>
              </div>
            </div>
          </div>
          <div style="margin-bottom: 1.25rem;clear: both;"></div>
        </div>
        <div style="height:100px;"></div>
        <p v-show="infiniteMsgShow" class="tips">加载下一页</p>
        <p v-show="!infiniteMsgShow" class="tips">没有更多数据</p>
      </mt-loadmore>
      <div v-if="!contentShow">
        <p class="empty">暂时没找到相应的商品</p>
      </div>
    </div>
    <!-- 底部	 -->
    <div class="dark-foot"></div>
  </div>
</template>

<script>
import { Indicator } from "mint-ui";
//import { Toast } from "mint-ui";
export default {
  data() {
    return {
      busy: true,
      page: 0,
      limit: 10,
      contentShow: "",
      infiniteMsgShow: true,
      allLoaded: true,
      productDataList: [],
      statusProduct: "商品列表"
    };
  },
  created() {
    this.statusProduct = this.$route.params.name;
    this.loadMore();
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    // 当属性滚动的时候  加载  滚动加载
    loadMore() {
      this.busy = true; // 将无限滚动给禁用
      setTimeout(() => {
        //发送请求有时间间隔第一个滚动时间结束后才发送第二个请求
        this.page++; //滚动之后加载第二页
        this.selProductList();
      }, 500);
    },
    //列表页
    selProductList() {
      if (this.statusProduct == null) {
        this.statusProduct = localStorage.name;
      }
      console.log(this.statusProduct);
      Indicator.open({ spinnerType: "fading-circle" });
      let me = this;
      this.$axios
        .post(
          "/api/mall/goodsClassify",
          { name: this.statusProduct, page: this.page, limit: this.limit },
          { emulateJSON: true }
        )
        .then(kun => {
          console.log(kun);
          Indicator.close();
          let listTotal = kun.total;
          if (listTotal > 0) {
            me.contentShow = true;
          } else {
            me.contentShow = false;
          }
          me.productDataList = me.productDataList.concat(kun.data);
          let DownloadTotal = me.page * me.limit;
          let total = kun.total;

          if (DownloadTotal > total) {
            me.busy = true; // 将无限滚动关闭
            me.page = 0; // 页数变为0
            me.infiniteMsgShow = false; // 切换底部提示信息
          } else {
            me.busy = false; // 当还有多余的数据时，将无限滚动给打开 ，就是可以继续滚动去请求后台
            me.infiniteMsgShow = true;
          }

          /* if (kun.code != 200) {
            Toast(kun.msg);
          } */
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    goGoodsDetails(val) {
      localStorage.sp_id = val;
      //到详情页
      this.$router.push({
        name: "ProductDetails",
        params: { sp_id: val }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
h3,
h4 {
  margin: 0;
  padding: 0;
}
//下拉 没有数据
.empty {
  font-size: 0.875rem;
  color: #999999;
  text-align: center;
  margin-top: 5.25rem;
}
//下拉 加载下一页
.tips {
  font-size: 0.875rem;
  color: #999999;
  text-align: center;
  margin: 1.25rem 0;
}
.box_left {
  float: left;
}
.box_right {
  float: right;
}
/* 头部 */
.dark-top {
  width: 100%;
  height: 2.75rem;
  color: #ffffff;
  position: fixed;
  top: 0;
  z-index: 9999;
  /* 设置渐变 */
  background: rgb(255, 0, 0); /* Old browsers */
  background: -moz-linear-gradient(
    to right bottom,
    rgb(255, 127, 95) 10%,
    rgb(229, 39, 77) 70%
  ); /* FF3.6-15 */
  background: -webkit-linear-gradient(
    to right bottom,
    rgb(255, 127, 95) 10%,
    rgb(229, 39, 77) 70%
  ); /* Chrome10-25,Safari5.1-6 */
  background: linear-gradient(
    to right bottom,
    rgb(255, 127, 95) 10%,
    rgb(229, 39, 77) 70%
  ); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */

  .page-back {
    width: 0.5625rem;
    height: 0.9375rem;
    text-decoration: none;
    color: #1a1a1a;
    display: inline-block;
    position: absolute;
    left: 0.9375rem;
    top: 1.0625rem;

    :first-child {
      width: 100%;
      height: 100%;
      background-image: url(../../assets/login/return-white.png);
      background-repeat: no-repeat;
      background-size: contain;
      background-position: center;
      overflow: hidden;
    }
  }

  .page-title {
    font-size: 20px;
    text-align: center;
    display: block;
    line-height: 1;
    position: absolute;
    top: 0.8rem;
    left: 50%;
    -ms-transform: translateX(-50%) translateY(0); /* IE 9 */
    -moz-transform: translateX(-50%) translateY(0); /* Firefox */
    -webkit-transform: translateX(-50%) translateY(0); /* Safari 和 Chrome */
    -o-transform: translateX(-50%) translateY(0); /* Opera */
  }
}

/* 内容 */
.hot_saleval {
  top: 4.125rem;
  width: 21.5625rem;
  height: 9.0625rem;
  margin: 0 auto;
  margin-top: 0.625rem;
  position: relative;
  border-bottom: 0.0625rem solid rgba(0, 0, 0, 0.05);

  .hot_content_box {
    height: 8.125rem;
    margin-bottom: 0.9375rem;
    clear: both;
    .hot_div_img {
      width: 5.625rem;

      :first-child {
        width: 100%;
        height: 8.125rem;
        background-image: url(../../assets/shop/spimg.png);
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
        overflow: hidden;
      }
    }
    .hot_div_brief {
      width: 15.3125rem;
      height: 8.125rem;
      color: #1a1a1a;
      position: relative;

      p {
        margin: 0.625rem 0;
        color: #9c9c9c;
        font-size: 0.75rem;
      }
      div {
        position: absolute;
        bottom: 0;
        width: 100%;
      }
      .span_yuan {
        color: #ff2000;
        font-weight: bold;
        font-size: 1.125rem;
      }
      .span_button {
        float: right;
        width: 3.5625rem;
        height: 1.125rem;
        text-align: center;
        line-height: 1.125rem;
        background-color: #ff2000;
        border-radius: 1.125rem;
        color: #ffffff;
        font-size: 0.75rem;
      }
    }
  }
}
</style>
